package com.re6g3y.dl4j.core;

import com.badlogic.gdx.Gdx;
import org.deeplearning4j.gym.StepReply;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;

public class Client<T,S> {
    public BlockingQueue<StepReply<S>> stepReplyQue=new SynchronousQueue<StepReply<S>>(true);
    public StepReply<S> getStepReply(){
        try {
            return stepReplyQue.take();
        } catch (InterruptedException e) {
            throw new RuntimeException(e.getMessage());
        }
    }
    public void setStepReply(StepReply<S> t){
        try {
            stepReplyQue.put(t);
        } catch (InterruptedException e) {
            throw new RuntimeException(e.getMessage());
        }
    }
    public BlockingQueue<T> actQue=new SynchronousQueue<T>(true);
    public T getAction(){
        try {
            return actQue.take();
        } catch (InterruptedException e) {
            throw new RuntimeException(e.getMessage());
        }
    }
    public void setAction(T t){
        try {
            actQue.put(t);
        } catch (InterruptedException e) {
            throw new RuntimeException(e.getMessage());
        }
    }

    public boolean isReset() {
        if(!resetFlag)return false;
        else resetFlag=false;
        return true;
    }
    public void reset() {
        resetFlag = true;
    }
    private boolean resetFlag=true;

    public void exit(){
        Gdx.app.exit();
    }
}
